package com.didd.core.common.base;

import lombok.AllArgsConstructor;
import lombok.Setter;
import lombok.ToString;

/**
 * <p>
 *  特殊的Result
 *  在抛出非定义枚举异常时,返回可读的异常消息
 * </p>
 * @author diddd
 * @since 2019/10/12
 */
@Setter
@ToString
@AllArgsConstructor
public class ResultSpecialCode implements ResultStatus {

    /**
     * return code
     */
    private int code;
    /**
     * return status
     */
    private String status;
    /**
     * return warning
     */
    private String message;

    @Override
    public int fetchCode() {
        return this.code;
    }

    @Override
    public String fetchStatus() {
        return this.status;
    }

    @Override
    public String fetchMessage() {
        return this.message;
    }

    /**
     * 构造业务异常
     * @param message 自定义的异常消息
     */
    public ResultSpecialCode(String message) {
        // 定义业务异常
        ResultStatus resultStatus = ResultCode.FAIL_BIZ;
        this.code = resultStatus.fetchCode();
        this.status = resultStatus.fetchStatus();
        // 重写业务异常消息
        this.message = message;
    }
}
